//
//  LGTPostDetailTitleViewCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/27.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTPostDetailTitleViewCell: UITableViewCell {

    var userImage:UIImageView?
    var userLabel:UILabel?
    var titlelabel:UILabel?
    var moneyLabel:UILabel?
    var typeLabel:UILabel?
    var osTyepLabel:UILabel?
    var leastTimeLabel:UILabel?
    
    private var _model:Dictionary<String, Any>?
    var model:Dictionary<String, Any>{
        get{
            return _model ?? Dictionary.init()
        }set{
            _model = newValue
            self.setData()
        }
    }
    
    func setData(){
        self.titlelabel?.text = self.model["projectName"] as? String ?? ""
        self.moneyLabel?.text = self.model["workPriceStr"] as? String ?? ""
        self.typeLabel?.text = self.model["typeStr"] as? String ?? ""
        self.osTyepLabel?.text = self.model["osStr"] as? String ?? ""
        self.leastTimeLabel?.text = self.model["taskCountStr"] as? String ?? ""
        self.userLabel?.text = self.model["name"] as? String ?? ""
        self.userImage?.setWebImage(url: (self.model["userUrl"] as? String ?? ""), nullType: 0)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }

    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        
        self.userImage = LGTViewCreateUtil.share.createImageViewCorner(corner: SizeFitFloat(16), imageName: "")
        self.addSubview(self.userImage!)
        self.userImage!.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(13))
            make.height.width.equalTo(SizeFitFloat(32))
            make.top.equalTo(SizeFit(12))
        }
        
        self.userLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(15))
        self.addSubview(self.userLabel!)
        self.userLabel?.snp.makeConstraints({ (make) in
            make.left.equalTo(SizeFit(52))
            make.height.equalTo(SizeFitFloat(15))
            make.centerY.equalTo( self.userImage!.snp_centerYWithinMargins)
        })
        
        self.titlelabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(18))
        self.titlelabel?.font = Font_Bold_18
        UIFont.boldSystemFont(ofSize: SizeFitFloat(18))
        self.addSubview(self.titlelabel!)
        self.titlelabel?.numberOfLines = 0
        self.titlelabel!.snp.makeConstraints({ (make) in
            make.left.equalTo(SizeFitFloat(13))
            make.height.equalTo(SizeFitFloat(20))
            make.top.equalTo(SizeFitFloat(60))
            make.right.equalTo(SizeFitFloat(-11))
        })
        
        self.moneyLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: ColorUtil(color: 0xF73F1B), fontSize: SizeFitFloat(18))
        self.addSubview(self.moneyLabel!)
        self.moneyLabel!.snp.makeConstraints { (make) in
            make.top.equalTo(self.titlelabel!.snp_bottomMargin).offset(SizeFitFloat(16))
            make.left.equalTo(SizeFitFloat(13))
            make.height.equalTo(SizeFitFloat(18))
        }
        
        self.typeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: UIColor.white, fontSize: SizeFitFloat(10), text: "", corner: SizeFitFloat(8))
        self.addSubview(self.typeLabel!)
        self.typeLabel!.backgroundColor = YellowColor
        self.typeLabel!.snp.makeConstraints { (make) in
            make.top.equalTo(self.moneyLabel!.snp_bottomMargin).offset(SizeFitFloat(13))
            make.left.equalTo(SizeFitFloat(13))
            make.height.equalTo(SizeFitFloat(16))
        }
        
        self.osTyepLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: UIColor.white, fontSize: SizeFitFloat(10), text: "", corner: SizeFitFloat(8))
        self.addSubview(self.osTyepLabel!)
        self.osTyepLabel!.backgroundColor = BlueColor
        self.osTyepLabel!.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.typeLabel!)
            make.left.equalTo(self.typeLabel!.snp_rightMargin).offset(SizeFitFloat(10))
            make.height.equalTo(SizeFitFloat(16))
        }
        
        //剩余
        self.leastTimeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: UIColor.white, fontSize: SizeFitFloat(10), text: "", corner: SizeFitFloat(8))
        self.addSubview(self.leastTimeLabel!)
        self.leastTimeLabel!.backgroundColor = ColorUtil(color: 0x00B55F)
        self.leastTimeLabel!.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.typeLabel!)
            make.left.equalTo(self.osTyepLabel!.snp_rightMargin).offset(SizeFitFloat(10))
            make.height.equalTo(SizeFitFloat(16))
            //make.bottom.equalTo(-SizeFitFloat(12))
        }
        
        //bond_icon
        
        let iconView:UIImageView = LGTViewCreateUtil.share.createImageView(image: "bond_icon")
        self.addSubview(iconView)
        iconView.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(13))
            make.width.height.equalTo(SizeFitFloat(18))
            make.top.equalTo(self.leastTimeLabel!.snp_bottomMargin).offset(SizeFitFloat(15))
            make.bottom.equalTo(-SizeFitFloat(13))
        }
        
        let label:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: ColorUtil(color: 0x7AD12A), fontSize: SizeFitFloat(12), text: "已交保证金，赚钱有保障")
        self.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.centerY.equalTo(iconView)
            make.height.equalTo(SizeFitFloat(12))
            make.left.equalTo(iconView.snp_rightMargin).offset(SizeFitFloat(10))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
